<?php
namespace app\admin\controller;
use pidan\App;
use pidan\Request;
use app\common\model\admin\Login;
use pidan\captcha\facade\Captcha;
use app\admin\Controller;
use pidan\facade\Db;


class Index extends Controller
{
	public function initialize(){
	}
	public function cache(){
		//取的范围
		$region=input('request.region','','trim');
		$app=$this->app;

		$all=[];
		//平台数据
		if(empty($region) || $region=='mall') $all['mall']=Db::name('mall')->column('name,logo','id');
		//平台任务类型
		if(empty($region) || $region=='type') $all['type']=Db::name('type')->column('mall_id,name','id');

		//用户信息
		if(empty($region) || $region=='user') $all['user']=['email'=>token_session('admin_id'),'nickname'=>token_session('admin_username')];

		//语言包
		if(empty($region) || $region=='lang') {
			$lang=$app->make('lang');
			$lang->load($app->getAppPath() . 'lang/' . $lang->getLangSet() . '.php','getLoad');
			$all['lang']=$lang->get(null,[],'getLoad');
		}
		return $this->api($all);
	}

	public function logout(){
		token_session('admin_id',NULL);
		token_session('admin_username',NULL);
		return $this->code(0);
	}
	public function login(Request $request,App $app){
	    $admin=array();
        $admin['username']=$request->get('username','','trim');
        $admin['password']=$request->get('password','','trim');
        $admin['vercode']=$request->get('vercode','','trim');
	    $login=new Login();
	    //检查是否登陆
        if(!Captcha::check($admin['vercode'])){
            $res=array('code'=>1,'msg'=>'验证码不正确','data'=>array());
        }
        //登陆 设置session admin_id admin_username admin_token
        else{
            if($login->login($admin)){
                $res=array('code'=>0,'msg'=>'登入成功','data'=>array('access_token'=>access_token()));
            }else{
                $res=array('code'=>2,'msg'=>'登入失败','data'=>array());
            }
        }
        return $this->result($res);
    }
	public function menu(){
		$menu=[
						//商家列表 店铺管理 任务管理 商家充值 商家提现
						[
								'name'=> 'user',
								'title'=>'商家管理',
								'icon'=>'layui-icon-home',
								'list'=>[
										['title'=>'商家列表','jump'=>'seller/list'],
										['name'=>'homepage1','title'=>'店铺管理','jump'=>'store/list'],
										['name'=>'homepage2','title'=>'任务管理','jump'=>'home/homepage2'],
										['name'=>'homepage1','title'=>'商家充值','jump'=>'home/homepage1'],
										['name'=>'homepage2','title'=>'商家提现','jump'=>'home/homepage1'],
								]
						],
						[
								'title'=>'玩家管理',
								'icon'=>'layui-icon-user',
								'list'=>[
										['title'=>'玩家列表','jump'=>'user/user/list'],
										['name'=>'homepage1','title'=>'买号列表','jump'=>'user/user/list'],
										['name'=>'homepage2','title'=>'垫付游戏列表','jump'=>'home/homepage2'],
								]
						],
						[
								'title'=>'控制面板',
								'icon'=>'layui-icon-component',
								'list'=>[
										['title'=>'申诉列表','jump'=>'/'],
										['name'=>'homepage1','title'=>'公告列表','jump'=>'home/homepage1'],
										['name'=>'homepage2','title'=>'事件列表','jump'=>'home/homepage2'],
										['name'=>'homepage1','title'=>'消费记录','jump'=>'home/homepage1'],
										['name'=>'homepage2','title'=>'统计明细','jump'=>'home/homepage1'],
										['name'=>'homepage2','title'=>'邀请明细','jump'=>'home/homepage1'],
										['name'=>'homepage2','title'=>'黑名单','jump'=>'home/homepage1'],
								]
						],
						[
								'title'=>'文章管理',
								'icon'=>'layui-icon-template',
								'list'=>[
										['name'=>'homepage1','title'=>'文章列表','jump'=>'home/homepage1'],
										['name'=>'homepage2','title'=>'文章分类','jump'=>'home/homepage2'],
								]
						],
						[
								'name'=> 'admin',
								'title'=>'系统用户',
								'icon'=>'layui-icon-user',
								'list'=>[
										['title'=>'管理员列表','jump'=>'admin/user/list'],
										['name'=>'homepage1','title'=>'角色管理','jump'=>'admin/role'],
										['title'=>'管理日志','jump'=>'admin/log/list'],
								]
						],
						[
								'title'=>'系统设置',
								'icon'=>'layui-icon-set',
								'list'=>[
									['title'=>'基本设置','jump'=>'config/list'],
									['title'=>'多语言','jump'=>'lang/list'],
									['title'=>'平台列表','jump'=>'mall/list'],
									['title'=>'平台任务类型','jump'=>'type1/list'],
									['title'=>'广告列表','jump'=>'home/homepage1'],
									['name'=>'homepage1','title'=>'地区列表','jump'=>'home/homepage1'],
								]
						],
						array (
							'title' => '主页',
							'icon' => 'layui-icon-home',
							'list' =>
								array (
									0 =>
										array (
											'title' => '控制台',
											'jump' => '/',
										),
									1 =>
										array (
											'name' => 'homepage1',
											'title' => '主页一',
											'jump' => 'home/homepage1',
										),
									2 =>
										array (
											'name' => 'homepage2',
											'title' => '主页二',
											'jump' => 'home/homepage2',
										),
								),
						),
						array (
							'name' => 'component',
							'title' => '组件',
							'icon' => 'layui-icon-component',
							'list' =>
								array (
									0 =>
										array (
											'name' => 'grid',
											'title' => '栅格',
											'list' =>
												array (
													0 =>
														array (
															'name' => 'list',
															'title' => '等比例列表排列',
														),
													1 =>
														array (
															'name' => 'mobile',
															'title' => '按移动端排列',
														),
													2 =>
														array (
															'name' => 'mobile-pc',
															'title' => '移动桌面端组合',
														),
													3 =>
														array (
															'name' => 'all',
															'title' => '全端复杂组合',
														),
													4 =>
														array (
															'name' => 'stack',
															'title' => '低于桌面堆叠排列',
														),
													5 =>
														array (
															'name' => 'speed-dial',
															'title' => '九宫格',
														),
												),
										),
									1 =>
										array (
											'name' => 'button',
											'title' => '按钮',
										),
									2 =>
										array (
											'name' => 'form',
											'title' => '表单',
											'list' =>
												array (
													0 =>
														array (
															'name' => 'element',
															'title' => '表单元素',
														),
													1 =>
														array (
															'name' => 'group',
															'title' => '表单组合',
														),
												),
										),
									3 =>
										array (
											'name' => 'nav',
											'title' => '导航',
										),
									4 =>
										array (
											'name' => 'tabs',
											'title' => '选项卡',
										),
									5 =>
										array (
											'name' => 'progress',
											'title' => '进度条',
										),
									6 =>
										array (
											'name' => 'panel',
											'title' => '面板',
										),
									7 =>
										array (
											'name' => 'badge',
											'title' => '徽章',
										),
									8 =>
										array (
											'name' => 'timeline',
											'title' => '时间线',
										),
									9 =>
										array (
											'name' => 'anim',
											'title' => '动画',
										),
									10 =>
										array (
											'name' => 'auxiliar',
											'title' => '辅助',
										),
									11 =>
										array (
											'name' => 'layer',
											'title' => '通用弹层',
											'list' =>
												array (
													0 =>
														array (
															'name' => 'list',
															'title' => '功能演示',
														),
													1 =>
														array (
															'name' => 'special-demo',
															'title' => '特殊示例',
														),
													2 =>
														array (
															'name' => 'theme',
															'title' => '风格定制',
														),
												),
										),
									12 =>
										array (
											'name' => 'laydate',
											'title' => '日期时间',
											'list' =>
												array (
													0 =>
														array (
															'name' => 'demo1',
															'title' => '功能演示一',
														),
													1 =>
														array (
															'name' => 'demo2',
															'title' => '功能演示二',
														),
													2 =>
														array (
															'name' => 'theme',
															'title' => '设定主题',
														),
													3 =>
														array (
															'name' => 'special-demo',
															'title' => '特殊示例',
														),
												),
										),
									13 =>
										array (
											'name' => 'table-static',
											'title' => '静态表格',
											'jump' => 'component/table/static',
										),
									14 =>
										array (
											'name' => 'table',
											'title' => '表格组件',
											'list' =>
												array (
													0 =>
														array (
															'title' => '表格综合演示',
														),
													1 =>
														array (
															'name' => 'auto',
															'title' => '列宽自动分配',
														),
													2 =>
														array (
															'name' => 'data',
															'title' => '赋值已知数据',
														),
													3 =>
														array (
															'name' => 'tostatic',
															'title' => '转化静态表格',
														),
													4 =>
														array (
															'name' => 'resetPage',
															'title' => '自定义分页',
														),
													5 =>
														array (
															'name' => 'radio',
															'title' => '开启单选框',
														),
													6 =>
														array (
															'name' => 'cellEdit',
															'title' => '双击单元格编辑',
														),
													7 =>
														array (
															'name' => 'form',
															'title' => '加入表单元素',
														),
													8 =>
														array (
															'name' => 'style',
															'title' => '设置单元格样式',
														),
													9 =>
														array (
															'name' => 'fixed',
															'title' => '固定列',
														),
													10 =>
														array (
															'name' => 'parseData',
															'title' => '解析任意数据格式',
														),
													11 =>
														array (
															'name' => 'onrow',
															'title' => '行事件',
														),
													12 =>
														array (
															'name' => 'search',
															'title' => '外部搜索',
														),
													13 =>
														array (
															'name' => 'initSort',
															'title' => '设置初始排序',
														),
													14 =>
														array (
															'name' => 'cellEvent',
															'title' => '单元格事件',
														),
													15 =>
														array (
															'name' => 'thead',
															'title' => '复杂表头',
														),
												),
										),
									15 =>
										array (
											'name' => 'laypage',
											'title' => '分页',
											'list' =>
												array (
													0 =>
														array (
															'name' => 'demo1',
															'title' => '功能演示一',
														),
													1 =>
														array (
															'name' => 'demo2',
															'title' => '功能演示二',
														),
												),
										),
									16 =>
										array (
											'name' => 'dropdown',
											'title' => '下拉菜单',
										),
									17 =>
										array (
											'name' => 'upload',
											'title' => '上传',
											'list' =>
												array (
													0 =>
														array (
															'name' => 'demo1',
															'title' => '功能演示一',
														),
													1 =>
														array (
															'name' => 'demo2',
															'title' => '功能演示二',
														),
												),
										),
									18 =>
										array (
											'name' => 'transfer',
											'title' => '穿梭框',
										),
									19 =>
										array (
											'name' => 'tree',
											'title' => '树形组件',
										),
									20 =>
										array (
											'name' => 'colorpicker',
											'title' => '颜色选择器',
										),
									21 =>
										array (
											'name' => 'slider',
											'title' => '滑块组件',
										),
									22 =>
										array (
											'name' => 'rate',
											'title' => '评分',
										),
									23 =>
										array (
											'name' => 'carousel',
											'title' => '轮播',
										),
									24 =>
										array (
											'name' => 'flow',
											'title' => '流加载',
										),
									25 =>
										array (
											'name' => 'util',
											'title' => '工具',
										),
									26 =>
										array (
											'name' => 'code',
											'title' => '代码修饰',
										),
								),
						),
						array (
							'name' => 'template',
							'title' => '页面',
							'icon' => 'layui-icon-template',
							'list' =>
								array (
									0 =>
										array (
											'name' => 'personalpage',
											'title' => '个人主页',
											'jump' => 'template/personalpage',
										),
									1 =>
										array (
											'name' => 'addresslist',
											'title' => '通讯录',
											'jump' => 'template/addresslist',
										),
									2 =>
										array (
											'name' => 'caller',
											'title' => '客户列表',
											'jump' => 'template/caller',
										),
									3 =>
										array (
											'name' => 'goodslist',
											'title' => '商品列表',
											'jump' => 'template/goodslist',
										),
									4 =>
										array (
											'name' => 'msgboard',
											'title' => '留言板',
											'jump' => 'template/msgboard',
										),
									5 =>
										array (
											'name' => 'search',
											'title' => '搜索结果',
											'jump' => 'template/search',
										),
									6 =>
										array (
											'name' => 'reg',
											'title' => '注册',
											'jump' => 'user/reg',
										),
									7 =>
										array (
											'name' => 'login',
											'title' => '登入',
											'jump' => 'user/login',
										),
									8 =>
										array (
											'name' => 'forget',
											'title' => '忘记密码',
											'jump' => 'user/forget',
										),
									9 =>
										array (
											'name' => '404',
											'title' => '404 页',
											'jump' => 'template/tips/404',
										),
									10 =>
										array (
											'name' => 'error',
											'title' => '出错页',
											'jump' => 'template/tips/error',
										),
									11 =>
										array (
											'name' => '',
											'title' => '内嵌页面',
											'spread' => true,
											'list' =>
												array (
													0 =>
														array (
															'name' => '',
															'title' => 'iframe - Bing',
															'jump' => '/iframe/link/demo',
														),
												),
										),
								),
						),
						array (
							'name' => 'app',
							'title' => '应用',
							'icon' => 'layui-icon-app',
							'list' =>
								array (
									0 =>
										array (
											'name' => 'content',
											'title' => '内容系统',
											'list' =>
												array (
													0 =>
														array (
															'name' => 'list',
															'title' => '文章列表',
														),
													1 =>
														array (
															'name' => 'tags',
															'title' => '分类管理',
														),
													2 =>
														array (
															'name' => 'comment',
															'title' => '评论管理',
														),
												),
										),
									1 =>
										array (
											'name' => 'forum',
											'title' => '社区系统',
											'list' =>
												array (
													0 =>
														array (
															'name' => 'list',
															'title' => '帖子列表',
														),
													1 =>
														array (
															'name' => 'replys',
															'title' => '回帖列表',
														),
												),
										),
									2 =>
										array (
											'name' => 'message',
											'title' => '消息中心',
										),
									3 =>
										array (
											'name' => 'workorder',
											'title' => '工单系统',
											'jump' => 'app/workorder/list',
										),
								),
						),
						array (
							'name' => 'senior',
							'title' => '高级',
							'icon' => 'layui-icon-senior',
							'list' =>
								array (
									0 =>
										array (
											'name' => 'im',
											'title' => 'WebIM UI',
										),
									1 =>
										array (
											'name' => 'echarts',
											'title' => 'Echarts',
											'list' =>
												array (
													0 =>
														array (
															'name' => 'line',
															'title' => '折线图',
														),
													1 =>
														array (
															'name' => 'bar',
															'title' => '柱状图',
														),
													2 =>
														array (
															'name' => 'map',
															'title' => '地图',
														),
												),
										),
								),
						),
						array (
							'name' => 'user',
							'title' => '用户',
							'icon' => 'layui-icon-user',
							'list' =>
								array (
									0 =>
										array (
											'name' => 'user',
											'title' => '网站用户',
											'jump' => 'user/user/list',
										),
									1 =>
										array (
											'name' => 'administrators-list',
											'title' => '后台管理员',
											'jump' => 'user/administrators/list',
										),
									2 =>
										array (
											'name' => 'administrators-rule',
											'title' => '角色管理',
											'jump' => 'user/administrators/role',
										),
								),
						),
						array (
							'name' => 'set',
							'title' => '设置',
							'icon' => 'layui-icon-set',
							'list' =>
								array (
									0 =>
										array (
											'name' => 'system',
											'title' => '系统设置',
											'spread' => true,
											'list' =>
												array (
													0 =>
														array (
															'name' => 'website',
															'title' => '网站设置',
														),
													1 =>
														array (
															'name' => 'email',
															'title' => '邮件服务',
														),
												),
										),
									1 =>
										array (
											'name' => 'user',
											'title' => '我的设置',
											'spread' => true,
											'list' =>
												array (
													0 =>
														array (
															'name' => 'info',
															'title' => '基本资料',
														),
													1 =>
														array (
															'name' => 'password',
															'title' => '修改密码',
														),
												),
										),
								),
						),
						array (
							'name' => 'get',
							'title' => '关于',
							'icon' => 'layui-icon-auz',
							'jump' => 'system/about',
						),

					];
			return $this->api($menu);
	}
	public function phpinfo(){
		phpinfo();
		return ob_get_clean();
	}

	public function index(Request $request,App $app){	  
		include app_path().'/tpl/home.php';
        return ob_get_clean();
	}


}
